package wnhz.com.business;

import android.os.Message;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import wnhz.com.business.base.MyBaseActivity;
import wnhz.com.business.freeshop.fragment.FourthFragment;
import wnhz.com.business.freeshop.fragment.FristFragment;
import wnhz.com.business.freeshop.fragment.SecondFragment;
import wnhz.com.business.freeshop.fragment.ThridFragment;

public class ShengYiBangActivity extends MyBaseActivity implements View.OnClickListener {

    @BindView(R.id.shengyibang_fl)
    FrameLayout shengyibang_fl;
    @BindView(R.id.shengyibang_fth)
    FragmentTabHost mainTabhostF;

    private TextView textView;
    /**
     * 带状态选择器的图标
     */
    private int[] mTabSelectors = new int[]{R.drawable.bg_rbtn_1,
            R.drawable.bg_rbtn_2, R.drawable.bg_rbtn_3, R.drawable.bg_rbtn_5};
    private Class[] mFragments_f = new Class[]{FristFragment.class,
            SecondFragment.class, ThridFragment.class, FourthFragment.class};
    private String[] tabname_f = new String[]{"首页", "分类", "购物车", "我的"};

    @Override
    protected void handleMsg(Message msg) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sheng_yi_bang);
        ButterKnife.bind(this);
        mainTabhostF.setup(this, getSupportFragmentManager(), R.id.shengyibang_fl);
        addTab();
    }


    /**
     * 添加底部按钮
     */
    private void addTab() {
        for (int i = 0; i < mFragments_f.length; i++) {
            View tabIndicator = getLayoutInflater().inflate(R.layout.rebate_indicator, null);//底部菜单布局
            ImageView imageView = (ImageView) tabIndicator.findViewById(R.id.imageView1);
            imageView.setImageResource(mTabSelectors[i]);
            TextView textView = (TextView) tabIndicator.findViewById(R.id.tv_names);
            textView.setText(tabname_f[i]);
            if (i == 2) {
                textView = (TextView) tabIndicator.findViewById(R.id.textView1);//右上角数量
            }
            mainTabhostF.addTab(mainTabhostF.newTabSpec(tabname_f[i]).setIndicator(tabIndicator), mFragments_f[i], null);
            tabIndicator.setId(i);
            tabIndicator.setOnClickListener(this);
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case 0:
                mainTabhostF.setCurrentTabByTag(tabname_f[0]);
                break;
            case 1:
                mainTabhostF.setCurrentTabByTag(tabname_f[1]);
                break;
            case 2:
                mainTabhostF.setCurrentTabByTag(tabname_f[2]);
                break;
            case 3:
                mainTabhostF.setCurrentTabByTag(tabname_f[3]);
                break;
        }
    }
}
